package com.gilt;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

import org.archive.crawler.datamodel.CandidateURI;
import org.archive.crawler.postprocessor.FrontierScheduler;

public class GiltFrontierScheduler extends FrontierScheduler {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	
	String regEx_women = "www\\.gilt\\.com/sale/women";
	String regEx_men = "www\\.gilt\\.com/sale/men";
	String regEx_children = "www\\.gilt\\.com/sale/children";
	String regEx_home = "www\\.gilt\\.com/sale/home";
	String regEx2 = "www\\.gilt\\.com/sale/[women,men,children,home]*";
	Pattern pat1 = Pattern.compile(regEx_women); 
	Pattern pat2 = Pattern.compile(regEx_men); 
	Pattern pat3 = Pattern.compile(regEx_children); 
	Pattern pat4 = Pattern.compile(regEx_home); 
	Matcher mat1 = null; 
	Matcher mat2 = null;
	Matcher mat3 = null;
	Matcher mat4 = null;

	public GiltFrontierScheduler(String name) {
		super(name);
	}
	
	protected void schedule(CandidateURI caUri) {
		String uri = caUri.toString();
		mat1 = pat1.matcher(uri);
		mat2 = pat2.matcher(uri);
		mat3 = pat3.matcher(uri);
		mat4 = pat4.matcher(uri);
		if("dns:www.gilt.com".equals(uri)){
			getController().getFrontier().schedule(caUri);
		}
		else if(mat1.find()){
			 getController().getFrontier().schedule(caUri);
		}
		else if(mat2.find()){
			 getController().getFrontier().schedule(caUri);
		}
		else if(mat3.find()){
			 getController().getFrontier().schedule(caUri);
		}
		else if(mat4.find()){
			 getController().getFrontier().schedule(caUri);
		}
       
    }
	
}
